import sys
from collections import defaultdict

def main():
    input = sys.stdin.read().split()
    ptr = 0
    T = int(input[ptr])
    ptr += 1
    for _ in range(T):
        n, m = int(input[ptr]), int(input[ptr+1])
        ptr +=2
        a = list(map(int, input[ptr:ptr+n]))
        ptr +=n

        count = defaultdict(int)
        count[0] = 1
        current_sum = 0
        ans = 0
        for num in a:
            current_sum += num
            r = (current_sum % m + m) % m  # 确保余数非负
            ans += count[r]
            count[r] += 1
        print(ans)

if __name__ == "__main__":
    main()